package com.ifinc.common.web.frame;

import com.ifinc.common.exception.ConfigException;

import java.util.HashMap;
import java.util.Map;

/**
 * User: luotao
 * Date: 13-11-28
 * Time: 13:23
 */
public class ClassManager {
    private Map<String, ClassInfo> classInfos = new HashMap<String, ClassInfo>();

    public ClassInfo loadClassInfos(String packageName, String className) {
        if (classInfos.get(packageName + className) == null) {
            synchronized (this) {
                if (classInfos.get(packageName + className) == null) {
                    ClassInfo classInfo = new ClassInfo(packageName, className);
                    boolean success = classInfo.loadClassInfo();
                    if (success) {
                        classInfos.put(packageName + className, classInfo);
                    }else{
                        throw new ConfigException("class not found %s",packageName+className);
                    }
                }
            }
        }
        ClassInfo classInfo = classInfos.get(packageName + className);
        return classInfo;
    }
}
